/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CompanyEntryForm.java
 *
 * Created on Jun 17, 2012, 1:14:42 PM
 */
package svp;

import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException;
import java.awt.Color;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.jdesktop.application.Action;
import svp.exceptions.NonexistentEntityException;
import svp.exceptions.PreexistingEntityException;

/**
 *
 * @author kandamaran
 */
public class CompanyEntryForm extends javax.swing.JDialog implements KeyListener, ActionListener {

    /** Creates new form CompanyEntryForm */
    public CompanyEntryForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        SVPPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("SVPPU").createEntityManager();
        customerCityStateQuery = java.beans.Beans.isDesignTime() ? null : SVPPUEntityManager.createQuery("SELECT c.city FROM CustomerCityState c ORDER BY c.city ASC");
        customerCityStateList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : customerCityStateQuery.getResultList();
        companyNameTblQuery = java.beans.Beans.isDesignTime() ? null : SVPPUEntityManager.createQuery("SELECT c.companyName FROM CompanyTbl c ORDER BY c.companyName ASC");
        companyTblList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : companyNameTblQuery.getResultList();
        companyCodeTblQuery = java.beans.Beans.isDesignTime() ? null : SVPPUEntityManager.createNamedQuery("CompanyTbl.code");
        companyCodeTblList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : companyCodeTblQuery.getResultList();
        customerStateQuery = java.beans.Beans.isDesignTime() ? null : SVPPUEntityManager.createQuery("SELECT DISTINCT(c.state) FROM CustomerCityState c ORDER BY c.state ASC");
        customerStateList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : customerStateQuery.getResultList();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        companyCodeCB = new javax.swing.JComboBox();
        companyNameCB = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        companyAddrTA = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        companyCityCB = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        companyStateCB = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        companyPostalCodeTF = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        companyTINTF = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        companyGSTTF = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        companyVATTF = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        companyContactPersonTF = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        companyPh1TF = new javax.swing.JTextField();
        companyPh2TF = new javax.swing.JTextField();
        companyWebsiteTF = new javax.swing.JTextField();
        saveCompanyInfoBT = new javax.swing.JButton();
        cancelCompanyInfoBT = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        editCompanyDetailsBT = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(svp.SVPApp.class).getContext().getResourceMap(CompanyEntryForm.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setIconImage(null);
        setIconImages(null);
        setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        setName("Form"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(78, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        companyCodeCB.setEditable(true);
        companyCodeCB.setFont(resourceMap.getFont("companyCodeCB.font")); // NOI18N
        companyCodeCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        companyCodeCB.setEnabled(false);
        companyCodeCB.setName("companyCodeCB"); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${resultList}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, companyCodeTblQuery, eLProperty, companyCodeCB);
        bindingGroup.addBinding(jComboBoxBinding);

        companyNameCB.setEditable(true);
        companyNameCB.setFont(resourceMap.getFont("companyNameCB.font")); // NOI18N
        List companyNameList = SVPPUEntityManager.createNamedQuery("CompanyTbl.name").getResultList();
        companyNameCB.setModel(new javax.swing.DefaultComboBoxModel(companyNameList.toArray()));
        new S17NonStrict(companyNameCB);
        JTextField companyNameTF = (JTextField) companyNameCB.getEditor().getEditorComponent();
        companyNameTF.setText("");
        companyNameCB.setName("companyNameCB"); // NOI18N
        companyNameCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                companyNameCBActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        companyAddrTA.setColumns(20);
        companyAddrTA.setFont(resourceMap.getFont("companyAddrTA.font")); // NOI18N
        companyAddrTA.setLineWrap(true);
        companyAddrTA.setRows(5);
        companyAddrTA.setWrapStyleWord(true);
        companyAddrTA.setAutoscrolls(false);
        companyAddrTA.setName("companyAddrTA"); // NOI18N
        jScrollPane1.setViewportView(companyAddrTA);

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setLabelFor(companyCityCB);
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        companyCityCB.setEditable(true);
        companyCityCB.setFont(resourceMap.getFont("companyCityCB.font")); // NOI18N
        companyCityCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        companyCityCB.setName("companyCityCB"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${resultList}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customerCityStateQuery, eLProperty, companyCityCB);
        bindingGroup.addBinding(jComboBoxBinding);

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setLabelFor(companyStateCB);
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        companyStateCB.setEditable(true);
        companyStateCB.setFont(resourceMap.getFont("companyStateCB.font")); // NOI18N
        companyStateCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item1", "Item2", "Item3", "Item4" }));
        companyStateCB.setName("companyStateCB"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${resultList}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customerStateQuery, eLProperty, companyStateCB);
        bindingGroup.addBinding(jComboBoxBinding);

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setLabelFor(companyPostalCodeTF);
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        companyPostalCodeTF.setFont(resourceMap.getFont("companyPostalCodeTF.font")); // NOI18N
        companyPostalCodeTF.setText(resourceMap.getString("companyPostalCodeTF.text")); // NOI18N
        companyPostalCodeTF.setName("companyPostalCodeTF"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        companyTINTF.setFont(resourceMap.getFont("companyTINTF.font")); // NOI18N
        companyTINTF.setText(resourceMap.getString("companyTINTF.text")); // NOI18N
        companyTINTF.setName("companyTINTF"); // NOI18N

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        companyGSTTF.setFont(resourceMap.getFont("companyGSTTF.font")); // NOI18N
        companyGSTTF.setText(resourceMap.getString("companyGSTTF.text")); // NOI18N
        companyGSTTF.setName("companyGSTTF"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        companyVATTF.setFont(resourceMap.getFont("companyVATTF.font")); // NOI18N
        companyVATTF.setText(resourceMap.getString("companyVATTF.text")); // NOI18N
        companyVATTF.setName("companyVATTF"); // NOI18N

        jLabel12.setFont(resourceMap.getFont("jLabel12.font")); // NOI18N
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        companyContactPersonTF.setFont(resourceMap.getFont("companyContactPersonTF.font")); // NOI18N
        companyContactPersonTF.setText(resourceMap.getString("companyContactPersonTF.text")); // NOI18N
        companyContactPersonTF.setName("companyContactPersonTF"); // NOI18N

        jLabel13.setFont(resourceMap.getFont("jLabel13.font")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setFont(resourceMap.getFont("jLabel15.font")); // NOI18N
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        companyPh1TF.setFont(resourceMap.getFont("companyPh1TF.font")); // NOI18N
        companyPh1TF.setText(resourceMap.getString("companyPh1TF.text")); // NOI18N
        companyPh1TF.setName("companyPh1TF"); // NOI18N

        companyPh2TF.setFont(resourceMap.getFont("companyPh2TF.font")); // NOI18N
        companyPh2TF.setText(resourceMap.getString("companyPh2TF.text")); // NOI18N
        companyPh2TF.setName("companyPh2TF"); // NOI18N

        companyWebsiteTF.setFont(resourceMap.getFont("companyWebsiteTF.font")); // NOI18N
        companyWebsiteTF.setText(resourceMap.getString("companyWebsiteTF.text")); // NOI18N
        companyWebsiteTF.setName("companyWebsiteTF"); // NOI18N

        saveCompanyInfoBT.setFont(resourceMap.getFont("saveCompanyInfoBT.font")); // NOI18N
        saveCompanyInfoBT.setText(resourceMap.getString("saveCompanyInfoBT.text")); // NOI18N
        saveCompanyInfoBT.setName("saveCompanyInfoBT"); // NOI18N
        saveCompanyInfoBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveCompanyInfoBTActionPerformed(evt);
            }
        });

        cancelCompanyInfoBT.setFont(resourceMap.getFont("cancelCompanyInfoBT.font")); // NOI18N
        cancelCompanyInfoBT.setText(resourceMap.getString("cancelCompanyInfoBT.text")); // NOI18N
        cancelCompanyInfoBT.setName("cancelCompanyInfoBT"); // NOI18N
        cancelCompanyInfoBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelCompanyInfoBTActionPerformed(evt);
            }
        });

        jCheckBox1.setSelected(true);
        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(svp.SVPApp.class).getContext().getActionMap(CompanyEntryForm.class, this);
        editCompanyDetailsBT.setAction(actionMap.get("editCompanyDetails")); // NOI18N
        editCompanyDetailsBT.setIcon(resourceMap.getIcon("editCompanyDetailsBT.icon")); // NOI18N
        editCompanyDetailsBT.setText(resourceMap.getString("editCompanyDetailsBT.text")); // NOI18N
        editCompanyDetailsBT.setName("editCompanyDetailsBT"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(114, 114, 114)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15)
                    .addComponent(jLabel14)
                    .addComponent(jLabel13)
                    .addComponent(jLabel12)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(saveCompanyInfoBT, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cancelCompanyInfoBT))
                    .addComponent(companyCityCB, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(companyStateCB, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(companyPostalCodeTF, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(companyWebsiteTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                            .addComponent(companyPh2TF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                            .addComponent(companyPh1TF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                            .addComponent(companyCodeCB, javax.swing.GroupLayout.Alignment.LEADING, 0, 236, Short.MAX_VALUE)
                            .addComponent(companyContactPersonTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                            .addComponent(companyVATTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(companyNameCB, javax.swing.GroupLayout.Alignment.LEADING, 0, 236, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(companyGSTTF, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(companyTINTF, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(editCompanyDetailsBT, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jCheckBox1))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(companyCodeCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editCompanyDetailsBT, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(companyNameCB)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(companyCityCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(companyStateCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(companyPostalCodeTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(companyTINTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(9, 9, 9)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(companyGSTTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(companyVATTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(companyContactPersonTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(companyPh1TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(companyPh2TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(companyWebsiteTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveCompanyInfoBT)
                    .addComponent(cancelCompanyInfoBT))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public String getNewCompanyCode(){
        String companyCode;
        int intCompanyCode;
        try{
        companyCode = SVPPUEntityManager.createNativeQuery("SELECT CAST(c.company_code as UNSIGNED) as ca FROM company_tbl c ORDER BY ca DESC LIMIT 1;").getResultList().get(0).toString();
        intCompanyCode = Integer.parseInt(companyCode) + 1;
        companyCode = String.valueOf(intCompanyCode);
        }catch(NullPointerException ne){
            ne.printStackTrace();
            companyCode = "1";
        }
        return companyCode; 
    }
    public boolean iscompanyNameInComboBoxAlreadyExist(){
       boolean companyNameExist = false;
     if(companyNameCB.getEditor().getItem().toString().equalsIgnoreCase("")== false ){
       List<String> companyNameList = SVPPUEntityManager.createNativeQuery("SELECT company_name FROM company_tbl").getResultList();
       
        for(String c: companyNameList){
           
           if(companyNameCB.getEditor().getItem().toString().equalsIgnoreCase(c) == true){
               companyNameExist = true;
               break;
           }
           
       } 
     }
     return companyNameExist;
     }
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
       
       
    }//GEN-LAST:event_formWindowOpened

    private void companyNameCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_companyNameCBActionPerformed
        // TODO add your handling code here:
          
       String companyCode = "", companyAddr = "", companyCity="", companyState="", companyPostalCode ="", companyTINNo=""
                            ,companyGSTNo="",companyContactPerson="",companyPH1="", companyPH2 ="",companyWebSite =""  ;
       Float companyVAT = new Float(0.00);
      
       jLabel2.setForeground(Color.black);
       jLabel2.setText("Add New/Edit Company Details Form.");
      
       if(this.iscompanyNameInComboBoxAlreadyExist()){
           saveCompanyInfoBT.setText("Update");
            try{ 
                
           String companyCodePK = SVPPUEntityManager.createNativeQuery("SELECT company_code FROM company_tbl WHERE company_name = '"+ companyNameCB.getEditor().getItem().toString() +"'" ).getResultList().get(0).toString(); ;
           CompanyTblJpaController cc = new CompanyTblJpaController(SVPPUEntityManager.getEntityManagerFactory());
           
           CompanyTbl c = cc.findCompanyTbl(companyCodePK);
           jLabel2.setForeground(Color.black);
           jLabel2.setText("Add New/Edit Company Details Form.");
           companyCode = c.getCompanyCode();
           companyAddr = c.getCompanyAddr() == null || c.getCompanyAddr().trim().equalsIgnoreCase("") ? "N/A" : c.getCompanyAddr();
           companyCity = c.getCompanyCity() == null || c.getCompanyCity().trim().equalsIgnoreCase("") ? "N/A" : c.getCompanyCity();
           companyState = c.getCompanyState() == null ||c.getCompanyState().trim().equalsIgnoreCase("") ? "N/A" : c.getCompanyState();
           companyPostalCode = c.getCompanypostalCode() == null || c.getCompanypostalCode().trim().equalsIgnoreCase("") ? "N/A" : c.getCompanypostalCode();
           companyTINNo = c.getCompanyTinno() == null || c.getCompanyTinno().trim().equalsIgnoreCase("") ? "N/A" : c.getCompanyTinno();
           companyGSTNo = c.getCompanyGstno() == null || c.getCompanyGstno().trim().equalsIgnoreCase("")? "N/A" : c.getCompanyGstno();
           companyVAT = c.getCompanyVat() == null ? new Float(0.00):c.getCompanyVat();
           companyContactPerson = c.getCompanycontactPerson() == null || c.getCompanycontactPerson().trim().equalsIgnoreCase("")? "N/A" : c.getCompanycontactPerson();
           companyPH1 = c.getCompanyphoneNo1() == null || c.getCompanyphoneNo1().trim().equalsIgnoreCase("")? "N/A" : c.getCompanyphoneNo1();
           companyPH2 = c.getCompanyphoneNo2()== null || c.getCompanyphoneNo2().trim().equalsIgnoreCase("")? "N/A" : c.getCompanyphoneNo2();
           companyWebSite = c.getCompanyWebsite()== null || c.getCompanyWebsite().trim().equalsIgnoreCase("")? "N/A" : c.getCompanyWebsite();
            companyCodeCB.getEditor().setItem(companyCode);
            companyAddrTA.setText(companyAddr);
            companyCityCB.getEditor().setItem(companyCity);
            companyStateCB.getEditor().setItem(companyState);
            companyPostalCodeTF.setText(companyPostalCode);
            companyTINTF.setText(companyTINNo);
            companyGSTTF.setText(companyGSTNo);
            companyVATTF.setText(String.valueOf(companyVAT));
            companyContactPersonTF.setText(companyContactPerson);
            companyPh1TF.setText(companyPH1);
            companyPh2TF.setText(companyPH2);
            companyWebsiteTF.setText(companyWebSite); 
            }catch(Exception e){
               
             onError.sendError("Apologies for the inconvience, an error occured while fetching company details. Would you like to report "
                + "it to the developement team?", e, rootPane);
        
     }  
           
     } else{
            saveCompanyInfoBT.setText("Save");
            companyCodeCB.getEditor().setItem(this.getNewCompanyCode());
            companyAddrTA.setText(companyAddr);
            companyCityCB.getEditor().setItem(companyCity);
            companyStateCB.getEditor().setItem(companyState);
            companyPostalCodeTF.setText(companyPostalCode);
            companyTINTF.setText(companyTINNo);
            companyGSTTF.setText(companyGSTNo);
            companyVATTF.setText(String.valueOf(companyVAT));
            companyContactPersonTF.setText(companyContactPerson);
            companyPh1TF.setText(companyPH1);
            companyPh2TF.setText(companyPH2);
            companyWebsiteTF.setText(companyWebSite); 
       } 
     
       
    }//GEN-LAST:event_companyNameCBActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        // new S17NonStrict(companyCodeCB);
        new S17NonStrict(companyCodeCB);
        JTextField companyCodeTF = (JTextField) companyCodeCB.getEditor().getEditorComponent();
        companyCodeTF.setText(this.getNewCompanyCode());
        new S17NonStrict(companyNameCB);
       JTextField companyNameTF = (JTextField) companyNameCB.getEditor().getEditorComponent();
       companyNameTF.setText("");
       companyNameCB.getEditor().getEditorComponent().addKeyListener(this);
        jCheckBox1.nextFocus();
        new S17NonStrict(companyCityCB);
        JTextField companyCityTF = (JTextField)companyCityCB.getEditor().getEditorComponent();
        companyCityTF.setText("");
        new S17NonStrict(companyStateCB);
        JTextField companyStateTF = (JTextField)companyStateCB.getEditor().getEditorComponent();
        companyStateTF.setText("");
        companyAddrTA.setText("");
        companyPostalCodeTF.setText("");
        companyTINTF.setText("");
        companyGSTTF.setText("");
        companyVATTF.setText("");
        companyContactPersonTF.setText("");
        companyPh1TF.setText("");
        companyPh2TF.setText("");
        companyWebsiteTF.setText(""); 
        companyNameCB.setVisible(true);
        companyCityCB.setVisible(true);
        companyStateCB.setVisible(true);
        companyAddrTA.setBackground(Color.WHITE);
        companyPostalCodeTF.setBackground(Color.WHITE);
        companyTINTF.setBackground(Color.WHITE);
        companyGSTTF.setBackground(Color.WHITE);
        companyVATTF.setBackground(Color.WHITE);
        companyContactPersonTF.setBackground(Color.WHITE);
        companyPh1TF.setBackground(Color.WHITE);
        companyPh2TF.setBackground(Color.WHITE);
        companyWebsiteTF.setBackground(Color.WHITE);
        editCompanyDetailsBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/svp/resources/Editing.png")));  
        jLabel2.setForeground(Color.black);
        jLabel2.setText("Add New/Edit Company Details Form.");
        saveCompanyInfoBT.setText("Save");
    }//GEN-LAST:event_formComponentShown

private void saveCompanyInfoBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCompanyInfoBTActionPerformed
    CompanyTblJpaController cc = new CompanyTblJpaController(SVPPUEntityManager.getEntityManagerFactory());
    CompanyTbl ctbl = new CompanyTbl();
    String companyCode="";            
    String companyName="";
    String companyAddr;
    String companyCity;
    String companyState;
    String companyPostalCode;
    String companyTIN;
    String companyGST;
    String companyVAT;
    String companyContactPerson;
    String companyPh1;
    String companyPh2;
    String companyWebsite;
    try {
            companyCode = companyCodeCB.getEditor().getItem().toString().trim();            
            companyName = companyNameCB.getEditor().getItem().toString().trim();
            companyAddr = companyAddrTA.getText().trim();
            companyCity = companyCityCB.getEditor().getItem().toString().trim();
            companyState = companyStateCB.getEditor().getItem().toString().trim();
            companyPostalCode = companyPostalCodeTF.getText().trim();
            companyTIN = companyTINTF.getText().trim();
            companyGST = companyGSTTF.getText().trim();
            companyVAT = companyVATTF.getText().trim();
            companyContactPerson = companyContactPersonTF.getText().trim();
            companyPh1 = companyPh1TF.getText().trim();
            companyPh2 = companyPh2TF.getText().trim();
            companyWebsite = companyWebsiteTF.getText().trim();
            ctbl.setCompanyCode(companyCode);
            ctbl.setCompanyName(companyName.toUpperCase());
            ctbl.setCompanyAddr(companyAddr.toUpperCase());
            ctbl.setCompanyCity(companyCity);
            ctbl.setCompanyState(companyState);
            ctbl.setCompanypostalCode(companyPostalCode);
            ctbl.setCompanyTinno(companyTIN);
            ctbl.setCompanyGstno(companyGST);
            ctbl.setCompanyVat(Float.parseFloat(companyVAT));
            ctbl.setCompanycontactPerson(companyContactPerson);
            ctbl.setCompanyphoneNo1(companyPh1);
            ctbl.setCompanyphoneNo2(companyPh2);
            ctbl.setCompanyWebsite(companyWebsite);
            cc.create(ctbl);
            this.getLatestCompanyNameListIntoCompanyNameCB();
            jLabel2.setForeground(Color.blue);
            jLabel2.setText("Company information has been saved!");
        } catch (PreexistingEntityException ex) {
                try {
                        ctbl.setCompanyName(companyNameEditingTF.getText().trim().toUpperCase());        
                        cc.edit(ctbl);
                        this.getLatestCompanyNameListIntoCompanyNameCB();
                        jLabel2.setForeground(Color.blue);
                        jLabel2.setText("Company information has been updated!");
                        this.removeCompanyNameEditMode();
                        companyNameCB.getEditor().setItem(companyNameEditingTF.getText().trim().toUpperCase());
                        
                } catch (Exception ex1) {
                        jLabel2.setForeground(Color.red);
                        jLabel2.setText("An Error Occured");
                        onError.sendError("Apologies for the inconvience, an error occured while saving company details. Would you like to report "
                                           + "it to the developement team?", ex, rootPane);
                         Logger.getLogger(CompanyEntryForm.class.getName()).log(Level.SEVERE, null, ex1);
                } 
            
        }catch (Exception ex) {
            Logger.getLogger(CompanyEntryForm.class.getName()).log(Level.SEVERE, null, ex);
            jLabel2.setForeground(Color.red);
            jLabel2.setText("An Error Occured");
             onError.sendError("Apologies for the inconvience, an error occured while saving company details. Would you like to report "
                               + "it to the developement team?", ex, rootPane);
        }
}//GEN-LAST:event_saveCompanyInfoBTActionPerformed

private void cancelCompanyInfoBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelCompanyInfoBTActionPerformed
    if (companyNameCB.getEditor().getItem().toString().trim().equalsIgnoreCase("")){
    this.dispose();
    }else {
       
         String message = "The Company info you entered has not been updated/saved, do you still want to close Company Entry Form?";
          int newType = JOptionPane.showConfirmDialog(rootPane, message,"Warning Message",JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
    
          if (newType == JOptionPane.YES_OPTION){
              this.dispose();
          }
    }
}//GEN-LAST:event_cancelCompanyInfoBTActionPerformed

    /**
     * @param args the command line arguments
     */
 //   public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
  //      try {
  //          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(CompanyEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(CompanyEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(CompanyEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(CompanyEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
        //</editor-fold>

        /* Create and display the dialog */
  //      java.awt.EventQueue.invokeLater(new Runnable() {

   //         public void run() {
  //              CompanyEntryForm dialog = new CompanyEntryForm(new javax.swing.JFrame(), true);
  //              dialog.addWindowListener(new java.awt.event.WindowAdapter() {

//                    @Override
 //                   public void windowClosing(java.awt.event.WindowEvent e) {
  //                      System.exit(0);
  //                  }
  //              });
   //             dialog.setVisible(true);
  //          }
//        });
//    }
    public void removeCompanyNameEditMode(){
      editCompanyDetailsBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/svp/resources/Editing.png")));  
      this.remove(companyNameEditingTF);
      companyNameCB.setVisible(true);
       
    }
    public void setCompanyNameCBToEditMode(){
        if (companyNameEditingTF.isShowing()== false){
              if (this.iscompanyNameInComboBoxAlreadyExist()){ 
                    editCompanyDetailsBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/svp/resources/1313907773_old-edit-undo.png")));  
                    companyNameCB.setVisible(false);
                    this.add(companyNameEditingTF); 
                    companyNameEditingTF.setBounds(companyNameCB.getBounds());
                    companyNameEditingTF.setBackground(Color.YELLOW);
                    companyNameEditingTF.setFont(companyNameCB.getFont());
                    companyNameEditingTF.setText(companyNameCB.getEditor().getItem().toString());
                    companyNameEditingTF.selectAll();
                    companyNameEditingTF.addKeyListener(this);
              }
              
      }else{ 
         this.removeCompanyNameEditMode();
      }
    }
    public void getLatestCompanyNameListIntoCompanyNameCB(){
        List companyNameList = SVPPUEntityManager.createNamedQuery("CompanyTbl.name").getResultList();
        companyNameCB.setModel(new javax.swing.DefaultComboBoxModel(companyNameList.toArray()));
        
    }
    @Action
    public void editCompanyDetails(){
       
      //if(editCompanyDetailsBT.getIcon().toString())
      // System.out.println("Icon - " + editCompanyDetailsBT.getIcon().toString());
      if (companyNameEditingTF.isShowing()== false){
              if (this.iscompanyNameInComboBoxAlreadyExist()){ 
                    editCompanyDetailsBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/svp/resources/1313907773_old-edit-undo.png")));  
                    companyNameCB.getEditor().getEditorComponent().removeKeyListener(this);
                    companyNameEditingTF.addKeyListener(this);
                    companyNameCB.setVisible(false);
                    companyNameEditingTF.setBounds(companyNameCB.getBounds());
                    companyNameEditingTF.setBackground(Color.YELLOW);
                    companyNameEditingTF.setFont(companyNameCB.getFont());
                    companyNameEditingTF.setText(companyNameCB.getEditor().getItem().toString());
                    this.add(companyNameEditingTF); 
                    cancelCompanyInfoBT.nextFocus();
                    companyNameEditingTF.selectAll();
                   // companyNameCB.add(companyNameEditingTF);
                   // companyNameCB.validate();
                    
                    
              }
              
      }else{
         companyNameEditingTF.removeKeyListener(this);
         companyNameCB.getEditor().getEditorComponent().addKeyListener(this);
         this.removeCompanyNameEditMode();
         jCheckBox1.nextFocus();
      }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager SVPPUEntityManager;
    private javax.swing.JButton cancelCompanyInfoBT;
    private javax.swing.JTextArea companyAddrTA;
    private javax.swing.JComboBox companyCityCB;
    private javax.swing.JComboBox companyCodeCB;
    private java.util.List<svp.CompanyTbl> companyCodeTblList;
    private javax.persistence.Query companyCodeTblQuery;
    private javax.swing.JTextField companyContactPersonTF;
    private javax.swing.JTextField companyGSTTF;
    private javax.swing.JComboBox companyNameCB;
    private javax.persistence.Query companyNameTblQuery;
    private javax.swing.JTextField companyPh1TF;
    private javax.swing.JTextField companyPh2TF;
    private javax.swing.JTextField companyPostalCodeTF;
    private javax.swing.JComboBox companyStateCB;
    private javax.swing.JTextField companyTINTF;
    private java.util.List<svp.CompanyTbl> companyTblList;
    private javax.swing.JTextField companyVATTF;
    private javax.swing.JTextField companyWebsiteTF;
    private java.util.List<svp.CustomerCityState> customerCityStateList;
    private javax.persistence.Query customerCityStateQuery;
    private java.util.List<svp.CustomerCityState> customerStateList;
    private javax.persistence.Query customerStateQuery;
    private javax.swing.JButton editCompanyDetailsBT;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton saveCompanyInfoBT;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    OnError onError = new OnError();
    JTextField companyNameEditingTF = new JTextField();
    JTextField companyCityEditingTF = new JTextField();
    JTextField companyStateEditingTF = new JTextField();
public void showOptionPane(String errorMessage, Exception e) {
this.dispose();   
SVPAboutBox aboutBox = new SVPAboutBox(SVPApp.getApplication().getMainFrame());
    int newType = JOptionPane.showConfirmDialog(rootPane,errorMessage,"Error",JOptionPane.YES_NO_OPTION);
    
   if (newType == JOptionPane.YES_OPTION){
            
                String com = aboutBox.sendReport(e);
                
                JOptionPane.showMessageDialog(rootPane, com);
                
            
      
  }else{
       this.dispose();
   }
   
}

@Action public void showAboutBox() {
    SVPAboutBox aboutBox = null;
        if (aboutBox == null) {
            JFrame mainFrame = SVPApp.getApplication().getMainFrame();
            aboutBox = new SVPAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }

          SVPApp.getApplication().show(aboutBox);

   }

    public void keyTyped(KeyEvent e) {
        
       if(this.iscompanyNameInComboBoxAlreadyExist()){
           saveCompanyInfoBT.setText("Update");
       }else{
          saveCompanyInfoBT.setText("Save"); 
       }
     
    }

    public void keyPressed(KeyEvent e) {
      // if(companyNameEditingTF.isShowing()==true){ 
            if(e.getKeyCode()== KeyEvent.VK_ESCAPE){
                
                
                editCompanyDetailsBT.doClick();
            }
            
             
      // }else{
           
      //     if(e.getKeyCode()== KeyEvent.VK_F2){
               
      //          editCompanyDetailsBT.doClick();
       //     }
     //  }
    }

    public void keyReleased(KeyEvent e) {
       
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("pressed key" + e.paramString());
       
    }



}
